<?php
/*公共函数集合*/


/* 日志功能 */
function DbgPrint($logfile, $logstring){
	$fp = fopen($logfile, "a");
	if( !$fp )
		return;
	fputs($fp, date("[Y-m-d H:i:s]\t"));
	fputs($fp, preg_replace("/[\r\n]/i", " ", $logstring) . "\r\n");
	fclose($fp);
}

/* 检查是否在发送邮件 */
function CheckSendMail(){
	$file = realpath("./lock/sendmail");
	if( !$file || !($fp = fopen($file, "r")) )
		return false;
	$lock = true;
	if( flock($fp, LOCK_NB | LOCK_SH) ){
		$lock = false;
		flock($fp, LOCK_UN);
	}
	fclose($fp);
	return $lock;
}

/*  打开URL */
function CreateThread($url){
	$fp = fsockopen("localhost", "80", $errno, $error);
	if( $fp ){
		fputs($fp, "GET {$url}\r\n");
		fputs($fp, "Host: localhost\r\n\r\n");
		fclose($fp);
		return true;
	} 
	return false;	
}

/* 生成UUID */
function uuid($prefix = '')
{
	$chars = md5(uniqid(mt_rand(), true));
	$uuid = substr($chars,0,8) . '-';
	$uuid .= substr($chars,8,4) . '-';
	$uuid .= substr($chars,12,4) . '-';
	$uuid .= substr($chars,16,4) . '-';
	$uuid .= substr($chars,20,12);
	return $prefix . $uuid;
}

?>